﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.BLL;
using CMS.BLL.Entity;

//ListItem item = new ListItem("Male", "1", true);
//ListItem item1 = new ListItem("Female", "0", true);
public partial class Controls_EntryVisa_ctrEntryVisa : System.Web.UI.UserControl
{
    private int nCurrentLang = Support.GetCurrentLanguage();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            setLable();
            SetValidate();
          BindDataToDay();
          //  BindDataToMonth();
      //      BindDataToYear(); 
           BindDataToYear1();
            BindDataToDDLFullNameTitle();
            BindDataToVisaPeriod();
            BindDataToNumbeOfEntry();
            BindDataToPaymentDropdown();
            BindDataToCustomerCountryDropdown();
            //BindDataToGender();
        }
    }
    private void SetValidate()
    {
        rfvContactEmail.ErrorMessage = MultipleLanguage.CONTACT_EMAIL_EMPTY[nCurrentLang - 1];
        rfvContactFullname.ErrorMessage = MessagesValidate.Setting_FULLNAME_EMPTY[nCurrentLang - 1];
        cpvEmail.ErrorMessage = MessagesValidate.COMPAREVALIDATEEMAIL[nCurrentLang - 1];
        revEmail.ErrorMessage = MessagesValidate.Setting_EMAIL_WRONG[nCurrentLang - 1];
    }
    protected void setLable()
    {
        int nCurrent = Support.GetCurrentLanguage();
        lblTitle.Text = MultipleLanguage.LBL_FULLNAMETILE[nCurrent - 1];
        lblArrivalDate.Text = MultipleLanguage.LBL_ARRIVIALDATE[nCurrent - 1];
        lblConfirmEmail.Text = MultipleLanguage.CONFIRMEMAIL[nCurrent - 1];
        lblContactFullname.Text = MultipleLanguage.LBL_FULLNAME[nCurrent - 1];
        lblDOB.Text = MultipleLanguage.LBL_DATEOFBIRTH[nCurrent - 1];
        lblEmail.Text = MultipleLanguage.EMAIL[nCurrent - 1];
        lblExitDate.Text = MultipleLanguage.LBL_EXITDATE[nCurrent - 1];
        lblExpiryDate.Text = MultipleLanguage.LBL_EXPIRYDATE[nCurrent - 1];
        lblFax.Text = MultipleLanguage.LBL_FAX[nCurrent - 1];
        lblFullName.Text = MultipleLanguage.LBL_FULLNAME[nCurrent - 1];
        lblGender.Text = MultipleLanguage.LBL_GENDER[nCurrent - 1];
        lblHomeAddress.Text = MultipleLanguage.LBL_HOMEADDRESS[nCurrent - 1];
        lblNationality.Text = MultipleLanguage.LBL_NATIONLITY[nCurrent - 1];
        lblNumberOfEntry.Text = MultipleLanguage.LBL_NUMBEROFENTRY[nCurrent - 1];
        lblOtherRequest.Text = MultipleLanguage.LBL_OTHERREQUEST[nCurrent - 1];
        lblPassportNo.Text = MultipleLanguage.LBL_PASSPORTNO[nCurrent - 1];
        lblPayment.Text = MultipleLanguage.LBL_PAYMENT[nCurrent - 1];
        lblPortOfArrival.Text = MultipleLanguage.PORTOFARRIVAL[nCurrent - 1];
        lblPurposeOfEntry.Text = MultipleLanguage.LBL_PURPOSEOFENTRY[nCurrent - 1];
        lblTel.Text = MultipleLanguage.LBL_TEL[nCurrent - 1];
        lblVisaPeriod.Text = MultipleLanguage.LBL_VISAPERIOD[nCurrent - 1];

     
        lblProposedDate.Text = MultipleLanguage.LBL_PROPOSEDDATE[nCurrent - 1];
        lblGroupDetails.Text = MultipleLanguage.LBL_GROUPDETAILS[nCurrent - 1];
        StaticPages objStaticPg = new StaticPages();
        StaticPages objStaticPg1 = new StaticPages();
        objStaticPg1.LoadById(37);
        objStaticPg.LoadById(38);
        
    }
    private void BindDataToCustomerCountryDropdown()
    {
        DataTable dtbCustomerCountry = new DataTable();
        CustomerCountry objCustomerCountry = new CustomerCountry();
        dtbCustomerCountry = objCustomerCountry.GetALL();

        ddlNationality1.DataSource = dtbCustomerCountry;
        ddlNationality1.DataValueField = "CountryID";
        ddlNationality2.DataSource = dtbCustomerCountry;
        ddlNationality2.DataValueField = "CountryID";
        ddlNationality3.DataSource = dtbCustomerCountry;
        ddlNationality3.DataValueField = "CountryID";
        ddlNationality4.DataSource = dtbCustomerCountry;
        ddlNationality4.DataValueField = "CountryID";
        ddlNationality5.DataSource = dtbCustomerCountry;
        ddlNationality5.DataValueField = "CountryID";
        ddlNationality6.DataSource = dtbCustomerCountry;
        ddlNationality6.DataValueField = "CountryID";
        ddlNationality7.DataSource = dtbCustomerCountry;
        ddlNationality7.DataValueField = "CountryID";
        ddlNationality8.DataSource = dtbCustomerCountry;
        ddlNationality8.DataValueField = "CountryID";
        switch (nCurrentLang)
        {
            case 1:
                ddlNationality1.DataTextField = "CountryName1";
                ddlNationality2.DataTextField = "CountryName1";
                ddlNationality3.DataTextField = "CountryName1";
                ddlNationality4.DataTextField = "CountryName1";
                ddlNationality5.DataTextField = "CountryName1";
                ddlNationality6.DataTextField = "CountryName1";
                ddlNationality7.DataTextField = "CountryName1";
                ddlNationality8.DataTextField = "CountryName1";
                break;
            case 2:
                ddlNationality1.DataTextField = "CountryName2";
                ddlNationality2.DataTextField = "CountryName2";
                ddlNationality3.DataTextField = "CountryName2";
                ddlNationality4.DataTextField = "CountryName2";
                ddlNationality5.DataTextField = "CountryName2";
                ddlNationality6.DataTextField = "CountryName2";
                ddlNationality7.DataTextField = "CountryName2";
                ddlNationality8.DataTextField = "CountryName2";
                break;
            case 3:
                ddlNationality1.DataTextField = "CountryName3";
                ddlNationality2.DataTextField = "CountryName3";
                ddlNationality3.DataTextField = "CountryName3";
                ddlNationality4.DataTextField = "CountryName3";
                ddlNationality5.DataTextField = "CountryName3";
                ddlNationality6.DataTextField = "CountryName3";
                ddlNationality7.DataTextField = "CountryName3";
                ddlNationality8.DataTextField = "CountryName3";
                break;
        }
        ddlNationality1.DataBind();
        ddlNationality2.DataBind();
        ddlNationality3.DataBind();
        ddlNationality4.DataBind();
        ddlNationality5.DataBind();
        ddlNationality6.DataBind();
        ddlNationality8.DataBind();
        ddlNationality7.DataBind();
    }
    private void BindDataToDDLFullNameTitle()
    {
        ListItem item = new ListItem("Mr.", "Mr.", true);
        ddlTitle.Items.Add(item);
        ListItem item1 = new ListItem("Miss.", "Miss.", true);
        ddlTitle.Items.Add(item1);
        ListItem item2 = new ListItem("Mrs.", "Mrs.", true);
        ddlTitle.Items.Add(item2);
        ListItem item3 = new ListItem("Ms.", "Ms.", true);
        ddlTitle.Items.Add(item3);
        ListItem item4 = new ListItem("Dr.", "Dr.", true);
        ddlTitle.Items.Add(item4);
    }
    private void BindDataToVisaPeriod()
    {
        ListItem item = new ListItem("1 Month", "1 Month", true);
        ddlVisaPeriod.Items.Add(item);
        ListItem item2 = new ListItem("3 Months", "3 Months", true);
        ddlVisaPeriod.Items.Add(item2);
        ListItem item3 = new ListItem("6 Months", "6 Months", true);
        ddlVisaPeriod.Items.Add(item3);
        ListItem item1 = new ListItem("12 Months", "12 Months", true);
        ddlVisaPeriod.Items.Add(item1);
    }
    private void BindDataToNumbeOfEntry()
    {
        ListItem item = new ListItem("Single", "Single", true);
        ddlNumberOfEntry.Items.Add(item);
        ListItem item1 = new ListItem("Multiple", "Multiple", true);
        ddlNumberOfEntry.Items.Add(item1);
    }
    //private void BindDataToGender()
    //{
    //    ListItem item = new ListItem("Male", "1", true);
    //    ListItem item1 = new ListItem("Female", "0", true);
    //    ddlGender11.Items.Add(item);
    //    ddlGender11.Items.Add(item1);
    //    ddlGender12.Items.Add(item);
    //    ddlGender12.Items.Add(item1);
    //    ddlGender13.Items.Add(item);
    //    ddlGender13.Items.Add(item1);
    //    ddlGender14.Items.Add(item);
    //    ddlGender14.Items.Add(item1);
    //    ddlGender15.Items.Add(item);
    //    ddlGender15.Items.Add(item1);
    //    ddlGender16.Items.Add(item);
    //    ddlGender16.Items.Add(item1);
    //    ddlGender17.Items.Add(item);
    //    ddlGender17.Items.Add(item1);
    //    ddlGender18.Items.Add(item);
    //    ddlGender18.Items.Add(item1);

    //}
    private void BindDataToPaymentDropdown()
    {
        DataTable dtbPayment = new DataTable();
        Payment objPayment = new Payment();
        dtbPayment = objPayment.GetAll();

        ddlPayment.DataSource = dtbPayment;
        ddlPayment.DataValueField = "PaymentID";
        ddlPayment.DataTextField = "Description";
        ddlPayment.DataBind();
    }
    private void BindDataToDay()
    {
        for (int i = 0; i < 31; i++)
        {
            ListItem item;
            if ((i + 1) < 10)
                item = new ListItem((i + 1).ToString(), "0" + (i + 1).ToString(), true);
            else
                item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlDay1.Items.Add(item);
            ddlDay2.Items.Add(item);
            //ddlDay10.Items.Add(item);
            
            //ddlDay3.Items.Add(item);
            //ddlDay4.Items.Add(item);
            //ddlDay5.Items.Add(item);
            //ddlDay6.Items.Add(item);
            //ddlDay7.Items.Add(item);
            //ddlDay8.Items.Add(item);
            //ddlDay9.Items.Add(item);
            //ddlExpiry1.Items.Add(item);
            //ddlExpiry2.Items.Add(item);
            //ddlExpiry3.Items.Add(item);
            //ddlExpiry4.Items.Add(item);
            //ddlExpiry5.Items.Add(item);
            //ddlExpiry6.Items.Add(item);
            //ddlExpiry7.Items.Add(item);
            //ddlExpiry8.Items.Add(item);
        }
    }
    //private void BindDataToMonth()
    //{
    //    for (int i = 0; i < 12; i++)
    //    {
    //        ListItem item;
    //        if ((i + 1) < 10)
    //            item = new ListItem((i + 1).ToString(), "0" + (i + 1).ToString(), true);
    //        else
    //            item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
    //        ddlMonth1.Items.Add(item);
    //        ddlMonth10.Items.Add(item);
    //        ddlMonth2.Items.Add(item);
    //        ddlMonth3.Items.Add(item);
    //        ddlMonth4.Items.Add(item);
    //        ddlMonth5.Items.Add(item);
    //        ddlMonth6.Items.Add(item);
    //        ddlMonth7.Items.Add(item);
    //        ddlMonth8.Items.Add(item);
    //        ddlMonth9.Items.Add(item);
    //        ddlExpiryMonth1.Items.Add(item);
    //        ddlExpiryMonth2.Items.Add(item);
    //        ddlExpiryMonth3.Items.Add(item);
    //        ddlExpiryMonth4.Items.Add(item);
    //        ddlExpiryMonth5.Items.Add(item);
    //        ddlExpiryMonth6.Items.Add(item);
    //        ddlExpiryMonth7.Items.Add(item);
    //        ddlExpiryMonth8.Items.Add(item);
    //    }
    //}
    //private void BindDataToYear()
    //{
    //    for (int i = 1939; i < 2000; i++)
    //    {
    //        ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
    //        ddlYear10.Items.Add(item);
    //        ddlYear3.Items.Add(item);
    //        ddlYear4.Items.Add(item);
    //        ddlYear5.Items.Add(item);
    //        ddlYear6.Items.Add(item);
    //        ddlYear7.Items.Add(item);
    //        ddlYear8.Items.Add(item);
    //        ddlYear9.Items.Add(item);
    //    }
    //}
    private void BindDataToYear1()
    {
        for (int i = 2011; i < 2020; i++)
        {
            ListItem item = new ListItem((i + 1).ToString(), (i + 1).ToString(), true);
            ddlYear1.Items.Add(item);
            ddlYear2.Items.Add(item);
            //ddlExpiryYear1.Items.Add(item);
            //ddlExpiryYear2.Items.Add(item);
            //ddlExpiryYear3.Items.Add(item);
            //ddlExpiryYear4.Items.Add(item);
            //ddlExpiryYear5.Items.Add(item);
            //ddlExpiryYear6.Items.Add(item);
            //ddlExpiryYear7.Items.Add(item);
            //ddlExpiryYear8.Items.Add(item);
        }
    }
   
    private eEntryVisa setData()
    {
        eEntryVisa objEntryVs = new eEntryVisa();
        objEntryVs.Address = txtHomeAddress.Text;
        
        objEntryVs.BookingDate = ConvertData.ConvertDatetimeToInt(DateTime.Today);
        objEntryVs.ConfirmEmail = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtConfirmEmail.Text));
        objEntryVs.DoB1 = ConvertData.ConvertDateStringToInt(txtDoB1.Text);
        objEntryVs.DoB2 = ConvertData.ConvertDateStringToInt(txtDoB2.Text);
        objEntryVs.DoB3 = ConvertData.ConvertDateStringToInt(txtDoB3.Text);
        objEntryVs.DoB4 = ConvertData.ConvertDateStringToInt(txtDoB4.Text);
        objEntryVs.DoB5 = ConvertData.ConvertDateStringToInt(txtDoB5.Text);
        objEntryVs.DoB6 = ConvertData.ConvertDateStringToInt(txtDoB6.Text);
        objEntryVs.DoB7 = ConvertData.ConvertDateStringToInt(txtDoB7.Text);
        objEntryVs.DoB8 = ConvertData.ConvertDateStringToInt(txtDoB8.Text);;

        objEntryVs.Email = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtEmail.Text));
        objEntryVs.ExitDate = ConvertData.ConvertDateStringToInt(ddlDay2.SelectedValue + "/" + ddlMonth2.SelectedValue + "/" + ddlYear2.SelectedValue);
        objEntryVs.ExpiryDate1 = ConvertData.ConvertDateStringToInt(txtExp1.Text);
        objEntryVs.ExpiryDate2 = ConvertData.ConvertDateStringToInt(txtExp2.Text);
        objEntryVs.ExpiryDate3 = ConvertData.ConvertDateStringToInt(txtExp3.Text);
        objEntryVs.ExpiryDate4 = ConvertData.ConvertDateStringToInt(txtExp4.Text);
        objEntryVs.ExpiryDate5 = ConvertData.ConvertDateStringToInt(txtExp5.Text);
        objEntryVs.ExpiryDate6 = ConvertData.ConvertDateStringToInt(txtExp6.Text);
        objEntryVs.ExpiryDate7 = ConvertData.ConvertDateStringToInt(txtExp7.Text);
        objEntryVs.ExpiryDate8 = ConvertData.ConvertDateStringToInt(txtExp8.Text);

        objEntryVs.Fax = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFax.Text));
        objEntryVs.FullName = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtContactFullname.Text));
        objEntryVs.FullName1 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName1.Text));
        objEntryVs.FullName2 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName2.Text));
        objEntryVs.FullName3 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName3.Text));
        objEntryVs.FullName4 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName4.Text));
        objEntryVs.FullName5 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName5.Text));
        objEntryVs.FullName6 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName6.Text));
        objEntryVs.FullName7 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName7.Text));
        objEntryVs.FullName8 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtFullName8.Text));

        objEntryVs.Gender1 = this.ConvertGender(txtGender1.Text);
        objEntryVs.Gender2 = this.ConvertGender(txtGender2.Text);
        objEntryVs.Gender3 = this.ConvertGender(txtGender3.Text);
        objEntryVs.Gender4 = this.ConvertGender(txtGender4.Text);
        objEntryVs.Gender5 = this.ConvertGender(txtGender5.Text);
        objEntryVs.Gender6 = this.ConvertGender(txtGender6.Text);
        objEntryVs.Gender7 = this.ConvertGender(txtGender7.Text);
        objEntryVs.Gender8 = this.ConvertGender(txtGender8.Text);

        objEntryVs.ArrivalDate = ConvertData.ConvertDateStringToInt(ddlDay1.SelectedValue + "/" + ddlMonth1.SelectedValue + "/" + ddlYear1.SelectedValue);

        int n1 = ddlNationality1.SelectedIndex;
        objEntryVs.Nationality1 = ConvertData.ConvertToString(ddlNationality1.Items[n1].Text);
        int n2 = ddlNationality2.SelectedIndex;
        objEntryVs.Nationality2 = ConvertData.ConvertToString(ddlNationality2.Items[n2].Text);
        int n3 = ddlNationality3.SelectedIndex;
        objEntryVs.Nationality3 = ConvertData.ConvertToString(ddlNationality3.Items[n3].Text);
        int n4 = ddlNationality4.SelectedIndex;
        objEntryVs.Nationality4 = ConvertData.ConvertToString(ddlNationality4.Items[n4].Text);
        int n5 = ddlNationality5.SelectedIndex;
        objEntryVs.Nationality5 = ConvertData.ConvertToString(ddlNationality5.Items[n5].Text);
        int n6 = ddlNationality6.SelectedIndex;
        objEntryVs.Nationality6 = ConvertData.ConvertToString(ddlNationality6.Items[n6].Text);
        int n7 = ddlNationality7.SelectedIndex;
        objEntryVs.Nationality7 = ConvertData.ConvertToString(ddlNationality7.Items[n7].Text);
        int n8 = ddlNationality8.SelectedIndex;
        objEntryVs.Nationality8 = ConvertData.ConvertToString(ddlNationality8.Items[n8].Text);

        int n9 = ddlVisaPeriod.SelectedIndex;
        objEntryVs.VisaPeriod = ConvertData.ConvertToString(ddlVisaPeriod.Items[n9].Text);
        int n10 = ddlNumberOfEntry.SelectedIndex;
        objEntryVs.NumberOfEntry = ConvertData.ConvertToString(ddlNumberOfEntry.Items[n10].Text);

        objEntryVs.OtherRequest = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtOtherRequest.Text));
        objEntryVs.PassportNo1 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPassport1.Text));
        objEntryVs.PassportNo2 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPassport2.Text));
        objEntryVs.PassportNo3 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPassport3.Text));
        objEntryVs.PassportNo4 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPassport4.Text));
        objEntryVs.PassportNo5 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPassport5.Text));
        objEntryVs.PassportNo6 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPassport6.Text));
        objEntryVs.PassportNo7 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPassport7.Text));
        objEntryVs.PassportNo8 = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtPassport8.Text));

        objEntryVs.PaymentID = ConvertData.ConvertToInt(ddlPayment.SelectedValue);
        objEntryVs.PortOfArrival = ConvertData.ConvertToString(txtPortOfArrival.Text);
        objEntryVs.PurposeOfEntry = ConvertData.ConvertToString(txtPurposeOfEntry.Text);
        objEntryVs.Status = 0;
        objEntryVs.Tel = ConvertData.ConvertToString(ConvertData.RemoveHTMLTag(txtTel.Text));
        

        return objEntryVs;
    }

    private int ConvertGender(string sGender)
    {
        int nResult = -1;
        switch (sGender)
        { 
            case "M":
                nResult = 1;
                break;
            case "F":
                nResult = 0;
                break;
        
        }
        if (nResult <0)
            nResult = 1;

        return nResult;
    }

    private void resetTextbox()
    {
        txtConfirmEmail.Text = "";
        txtContactFullname.Text = "";
        txtEmail.Text = "";
        txtFax.Text = "";
        txtFullName1.Text = "";
        txtFullName2.Text = "";
        txtFullName3.Text = "";
        txtFullName4.Text = "";
        txtFullName5.Text = "";
        txtFullName6.Text = "";
        txtFullName7.Text = "";
        txtFullName8.Text = "";
        txtHomeAddress.Text = "";
        txtOtherRequest.Text = "";
        txtPassport1.Text = "";
        txtPassport2.Text = "";
        txtPassport3.Text = "";
        txtPassport4.Text = "";
        txtPassport5.Text = "";
        txtPassport6.Text = "";
        txtPassport7.Text = "";
        txtPassport8.Text = "";
        txtPortOfArrival.Text = "";
        txtPurposeOfEntry.Text = "";
        txtTel.Text = "";
    }
    protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        EntryVisa objEntryVisa = new EntryVisa();
        objEntryVisa.Data = this.setData();
        int nID = objEntryVisa.Insert();
        if (nID >0)
        {
            resetTextbox();
            Response.Redirect("~/EntryVisa.aspx?msg=1");
          //  ScriptManager.RegisterStartupScript(Page, Page.GetType(), "AnUniqueKey", MultipleLanguage.ENTRYVISA_SENT[nCurrentLang-1], true);
        }
    }
}
